package com.woniuxy.oa.web;

import com.github.pagehelper.PageInfo;
import com.woniuxy.oa.entity.Dept;
import com.woniuxy.oa.entity.ResponseVO;
import com.woniuxy.oa.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Auther: M
 * @Date: 2019/12/24 19:28
 * @Description:
 */
@CrossOrigin("*")
@Controller
@RequestMapping("dept")
public class DeptController {
    @Autowired
    private DeptService deptService;

    @PostMapping("list")
    @ResponseBody
    public ResponseVO list(@RequestBody Dept dept){
        System.out.println(dept);
        ResponseVO responseVO=new ResponseVO();
        PageInfo<Dept> depts=deptService.getAll(dept);
        responseVO.setCode("200");
        responseVO.setData(depts);
        return responseVO;
    }
    @GetMapping("del/{deptId}")
    @ResponseBody
    public ResponseVO del(@PathVariable String deptId){
        System.out.println(deptId);
        ResponseVO responseVO=new ResponseVO();
        deptService.del(deptId);
        responseVO.setCode("200");
        return responseVO;
    }
    @PostMapping("add")
    @ResponseBody
    public ResponseVO add(@RequestBody Dept dept){
        ResponseVO responseVO=new ResponseVO();
        for(Integer id:dept.getIds()){
            System.out.println(id);
        }
        deptService.add(dept);
        responseVO.setCode("200");
        return responseVO;
    }
    @GetMapping("sel/{deptId}")
    @ResponseBody
    public ResponseVO list(@PathVariable String deptId){
        System.out.println(deptId);
        ResponseVO responseVO=new ResponseVO();
        Dept dept=deptService.getAllDeptById(deptId);
        responseVO.setCode("200");
        responseVO.setData(dept);
        return responseVO;
    }

    @PostMapping("update")
    @ResponseBody
    public ResponseVO update(@RequestBody Dept dept){
        System.out.println(dept);
        ResponseVO responseVO=new ResponseVO();
        deptService.update(dept);
        return responseVO;
    }
    @GetMapping("all")
    @ResponseBody
    public ResponseVO all(){
        ResponseVO responseVO=new ResponseVO();
        List<Dept> depts=deptService.getAll();
        responseVO.setCode("200");
        responseVO.setData(depts);
        return responseVO;
    }
}